<%
  system.SetSessionVar("sessionTAB", "startpage");
%>

<script type="text/javascript">

  <%
    var id                  = "";
    var userId              = system.GetSessionVar("sessionUserID");
    var oFavorites          = dom.GetObject(ID_FAVORITES);
    var bFavoritesAvailable = false;
    var oFavoriteIds        = "";
    
    if (oFavorites) 
    { 
      var oFavoriteList = oFavorites.Get("_USER" # userId);
      
      if ((oFavoriteList) && (0 < oFavoriteList.Count())) 
      {
        bFavoritesAvailable = true;
        sFavoriteIds        = oFavoriteList.EnumIDs();
      }
    }
    
  %>
 
 
  
</script>

<div id="startpage" class="CLASS01800">

  <!-- Linke Seite: Favoriten -->
  <div id="contentLeft" class="CLASS01802">
  
    <div class="CLASS01801">
  
      <!-- Favoritenliste -->
      <div id="favSelector" class="CLASS01803" style="display:none">&nbsp;
        <select class="SelectBox j_translate" onchange="WebUI.enter(StartPage, this.value);">
        <%
        string id = "";
        object oFavorites = dom.GetObject( ID_FAVORITES );
        if( oFavorites )
        {
          object oFavoriteList = oFavorites.Get( "_USER"#system.GetSessionVar("sessionUserID") );
          if( oFavoriteList )
          {
            if( oFavoriteList.Count() == 0 )
            { 
              Write( '<option>${noFav}</option>' ); 
            }
            string s;
            foreach(s,oFavoriteList.EnumIDs())
            {
              object oFavorite = dom.GetObject(s);
              if( oFavorite )
              {
                if( !id.Length() )
                {
                  if( system.IsVar("fid") )
                  {
                    id = system.GetVar("fid");
                    system.SetSessionVar("sessionFAV",system.GetVar("fid"));
                  }
                  else
                  {
                    if( system.IsSessionVar("sessionFAV") )
                    {
                      id = system.GetSessionVar("sessionFAV");
                      object oTmpTest = dom.GetObject( id );
                      if( !oTmpTest ) { id = oFavorite.ID(); }
                    }
                    else
                    {
                      id = oFavorite.ID();
                    }
                  }
                }
                string sSelected = "";
                if( id == oFavorite.ID() ) { sSelected = "selected";}
                Write( '<option '#sSelected#' value="'#oFavorite.ID()#'">' );
                Write( oFavorite.Name() );
                Write( '</option>' );
              }
            }
          }
        }
        %>
        </select>&nbsp;
      </div>
      
      <!-- Favoriten -->
      <div id="loadingGif"><img style="margin: 30px;" src="/ise/img/loading.gif" /></div>
      <div id="favView" class="CLASS01804" style="display:none">
        <div align="center">
        <table id="tblfav" cellpadding="0" cellspacing="0" class="CLASS01805">
        <tr>
        <%
        string sid;
        integer i = 0;
          object objX = dom.GetObject( system.GetVar("id") );
          if( objX )
          {
            if( objX.TypeName() == "FAVORITE" )
            {
              foreach( sid, objX.EnumIDs() )
              {
                object oEntry = dom.GetObject( sid );
                if( oEntry )
                {
                  Write('<td>');
                  Write('<table cellpadding="0" cellspacing="0" class="CLASS01806">');
                  Write('<tr>');
                  Write('<td class="CLASS01807">'#dom.GetObject(sid).Name()#'</td>');
                  Write('</tr>');
                  Write('<tr>');
                  Write('<td id="dpc'#oEntry.ID()#'" class="CLASS01812">');
                  integer cId = oEntry.ID();
                  integer iStatusOnly = 0;
                  boolean bInStatusList = false;
                  boolean bHasFullAccess = (oEntry.UserAccessRights(iulOtherThanAdmin) == iarFullAccess);
                  string s;
                  foreach(s,objX.FavControlIDs().EnumIDs() )
                  {
                    if( s == oEntry.ID().ToString() )
                    {
                      bInStatusList = true;
                    }
                  }
                  boolean bBoolVar = false;
                  if ( oEntry.IsTypeOf( OT_ALARMDP ) ) { bBoolVar = true;}
                  if ( oEntry.IsTypeOf( OT_VARDP ) && (oEntry.ValueSubType() == istBool) ) { bBoolVar = true; }
                  if (bInStatusList || bBoolVar || (!bHasFullAccess)) {
                    iStatusOnly = 1;
                  }
                  Call("/esp/datapointconfigurator.fn::dcCreate()");
                  Write('</td>');
                  Write('</tr>');
                  Write('</table>');
                  Write('</br>');
                  Write('</td>');
                  Write('</tr><tr>');
                  i = i + 1;
                }
              }
            }
          }
          else
          {
            Write("<td>Kann Favoriten nicht öffnen!</td>");
          }
        %>
        </tr>
        </table>
        </div>
     </div>
   
    </div>
    
  </div> 
   
  <!-- Rechte Seite: Anlern-Button, SystemInformationen -->
  <div id="contentRight" class="CLASS01809" style="overflow:auto;">

      <table id="tblRightContent" width="100%">
        <tr style="vertical-align: top;" class="CLASS01810">
          <td>
          <table id="tblStartpageInfo" width="100%" class="CLASS01811 startPageInfo hidden" cellpadding="2" cellspacing="0">
            <colgroup>
              <col style="width:30%;"/>
              <col />
            </colgroup>
            <tr>
                <!-- Uhrzeit -->
              <td>${time}:</td>
              <td><span id="maintime"><% Write(system.Date("%H:%M")); %></span><!-- Uhr--></td>
            </tr>
            <tr>
              <!--Datum -->
              <td>${date}:</td>
              <td><span id="maindate"><% Write(system.Date("%d.%m.%Y")); %></span></td>
            </tr>

            <tr>
            <!-- Sonnenaufgang -->
              <td>${sunrise}:</td>
              <td id="sunrise"><% Write(system.SunriseTime("%H:%M")); %><!-- Uhr --></td>
            </tr>

            <tr>
            <!-- Sonnenuntergang -->
              <td>${sunset}:</td>
              <td id="sunset"><% Write(system.SunsetTime("%H:%M")); %><!-- Uhr--></td>
            </tr>

            <tr>
              <td>${currentFirmwareVersion}</td>
             <!-- <td id="currentFirmware">${lblCurrentFirmwareVersionNotKnown}</td> -->
              <td id="currentFirmware">--</td>
            </tr>

            <tr id="updateRow" style="display:none;">
              <!-- CCU2-Update -->
              <td>${update}</td>
               <!-- Firmware ist verf&uuml;gbar -->
              <td colspan="3" id="updateCol">${newFirmwareAvailable}</td>
            </tr>

            <!-- Device-Firmware -->
            <tr id="devFwAvailable" class="hidden">
              <td>${deviceUpdate}</td>
              <td class="firmwareAvailable">${lblNewDeviceFirmwareAvailable}&nbsp;<span id="devFwAvailableCounter"></span></td>
            </tr>

            <%
              object oUser = dom.GetObject( system.GetSessionVar('sessionUserID') );
              if (oUser.UserPwd() == "")
              {
                Write("<tr>");

                  Write("<td>${login}:</td>");

                  Write("<td colspan='3' class='attention'>${noPasswd}</td>");
                Write("</tr>");
              }
              
              if (oUser) {
                string tmp;
                foreach ( tmp, oUser.UserSharedObjects().EnumIDs()) {
                  object oDP = dom.GetObject(tmp);
                  Write("<tr>");
                  Write("<td>"#oDP.Name()#":</td>");
                  Write("<td colspan='3' id='SYSVAR_" # tmp # "' >");
                  string sSysVarVal = "";
                  object cObjTmp = oDP;
                  integer iVT = oDP.ValueType();
                  integer iST = oDP.ValueSubType();
                  boolean bLogic  = ( (iVT==ivtBinary)  && (iST==istBool)    );
                  boolean bList   = ( (iVT==ivtInteger) && (iST==istEnum)    );
                  boolean bNumber = ( (iVT==ivtFloat)   && (iST==istGeneric) );
                  boolean bAlarm  = ( (iVT==ivtBinary)  && (iST==istAlarm)   );
                  boolean bString = ( (iVT==ivtString)  && (iST==istChar8859));
                  Call( "/esp/system.fn::getSysVarValAsString()" );
                  Write( sSysVarVal );
                  Write("</td>");
                  Write("</tr>");
                }
              }
             %>

            <!-- DutyCycle -->
            <tr>
              <td colspan="3"><hr/></td>
            </tr>
            <tr id="partingLine1" class="hidden" style="display:none;">
              <td></td>
              <td>
                <table style="width:100%;text-align:center;font-size:11px;" cellpadding="0" cellspacing="0">
                  <tbody>
                    <tr>
                      <td style="width:70%;">${lblDutyCycle}</td>
                      <td style="width:30%;">${lblCarrierSense}</td>
                    </tr>
                  </tbody>
                </table>
              </td>
            </tr>
            <tr name="trDutyCycle0" style="display: none">
              <td id="dutyCycleAddr0" style="vertical-align: top;text-align: left;"></td>
              <td><table style="width:100%"><tr>
                <td id="hmBootstrap" style="width:70%;margin-right: 0px;padding-right: 0px;"><div class="progress"><div name="dutyCycleBar0" class="progress-bar" role="progressbar" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100" style="width:0%"><span id="dutyCycleVal0"></span></div></div></td>
                <td id="hmBootstrap" style="width:30%"><div class="progress" name="carrierSenseCol0"><div name="carrierSenseBar0" class="progress-bar bg-info" role="progressbar" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100" style="width:0%"><span id="carrierSenseVal0"></span></div></div></td> 
              </tr></table></td>
            </tr>
            <tr name="trDutyCycle1" style="display: none">
              <td id="dutyCycleAddr1" style="vertical-align: top;text-align: left;"></td>
              <td><table style="width:100%"><tr>
                <td id="hmBootstrap" style="width:70%;margin-right: 0px;padding-right: 0px;"><div class="progress"><div name="dutyCycleBar1" class="progress-bar" role="progressbar" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100" style="width:0%"><span id="dutyCycleVal1"></span></div></div></td>
                <td id="hmBootstrap" style="width:30%"><div class="progress" name="carrierSenseCol1"><div name="carrierSenseBar1" class="progress-bar bg-info" role="progressbar" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100" style="width:0%"><span id="carrierSenseVal1"></span></div></div></td> 
              </tr></table></td>
            </tr>
            <tr name="trDutyCycle2" style="display: none">
              <td id="dutyCycleAddr2" style="vertical-align: top;text-align: left;"></td>
              <td><table style="width:100%"><tr>
                <td id="hmBootstrap" style="width:70%;margin-right: 0px;padding-right: 0px;"><div class="progress"><div name="dutyCycleBar2" class="progress-bar" role="progressbar" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100" style="width:0%"><span id="dutyCycleVal2"></span></div></div></td>
                <td id="hmBootstrap" style="width:30%"><div class="progress" name="carrierSenseCol2"><div name="carrierSenseBar2" class="progress-bar bg-info" role="progressbar" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100" style="width:0%"><span id="carrierSenseVal2"></span></div></div></td> 
              </tr></table></td>
            </tr>
            <tr name="trDutyCycle3" style="display: none">
              <td id="dutyCycleAddr3" style="vertical-align: top;text-align: left;"></td>
              <td><table style="width:100%"><tr>
                <td id="hmBootstrap" style="width:70%;margin-right: 0px;padding-right: 0px;"><div class="progress"><div name="dutyCycleBar3" class="progress-bar" role="progressbar" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100" style="width:0%"><span id="dutyCycleVal3"></span></div></div></td>
                <td id="hmBootstrap" style="width:30%"><div class="progress" name="carrierSenseCol3"><div name="carrierSenseBar3" class="progress-bar bg-info" role="progressbar" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100" style="width:0%"><span id="carrierSenseVal3"></span></div></div></td> 
              </tr></table></td>
            </tr>
            <tr name="trDutyCycle4" style="display: none">
              <td id="dutyCycleAddr4" style="vertical-align: top;text-align: left;"></td>
              <td><table style="width:100%"><tr>
                <td id="hmBootstrap" style="width:70%;margin-right: 0px;padding-right: 0px;"><div class="progress"><div name="dutyCycleBar4" class="progress-bar" role="progressbar" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100" style="width:0%"><span id="dutyCycleVal4"></span></div></div></td>
                <td id="hmBootstrap" style="width:30%"><div class="progress" name="carrierSenseCol4"><div name="carrierSenseBar4" class="progress-bar bg-info" role="progressbar" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100" style="width:0%"><span id="carrierSenseVal4"></span></div></div></td> 
              </tr></table></td>
            </tr>
            <tr name="trDutyCycle5" style="display: none">
              <td id="dutyCycleAddr5" style="vertical-align: top;text-align: left;"></td>
              <td><table style="width:100%"><tr>
                <td id="hmBootstrap" style="width:70%;margin-right: 0px;padding-right: 0px;"><div class="progress"><div name="dutyCycleBar5" class="progress-bar" role="progressbar" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100" style="width:0%"><span id="dutyCycleVal5"></span></div></div></td>
                <td id="hmBootstrap" style="width:30%"><div class="progress" name="carrierSenseCol5"><div name="carrierSenseBar5" class="progress-bar bg-info" role="progressbar" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100" style="width:0%"><span id="carrierSenseVal5"></span></div></div></td> 
              </tr></table></td>
            </tr>
            <tr name="trDutyCycle6" style="display: none">
              <td id="dutyCycleAddr6" style="vertical-align: top;text-align: left;"></td>
              <td><table style="width:100%"><tr>
                <td id="hmBootstrap" style="width:70%;margin-right: 0px;padding-right: 0px;"><div class="progress"><div name="dutyCycleBar6" class="progress-bar" role="progressbar" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100" style="width:0%"><span id="dutyCycleVal6"></span></div></div></td>
                <td id="hmBootstrap" style="width:30%"><div class="progress" name="carrierSenseCol6"><div name="carrierSenseBar6" class="progress-bar bg-info" role="progressbar" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100" style="width:0%"><span id="carrierSenseVal6"></span></div></div></td> 
              </tr></table></td>
            </tr>
            <tr name="trDutyCycle7" style="display: none">
              <td id="dutyCycleAddr7" style="vertical-align: top;text-align: left;"></td>
              <td><table style="width:100%"><tr>
                <td id="hmBootstrap" style="width:70%;margin-right: 0px;padding-right: 0px;"><div class="progress"><div name="dutyCycleBar7" class="progress-bar" role="progressbar" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100" style="width:0%"><span id="dutyCycleVal7"></span></div></div></td>
                <td id="hmBootstrap" style="width:30%"><div class="progress" name="carrierSenseCol7"><div name="carrierSenseBar7" class="progress-bar bg-info" role="progressbar" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100" style="width:0%"><span id="carrierSenseVal7"></span></div></div></td> 
              </tr></table></td>
            </tr>
            <tr name="trDutyCycle8" style="display: none">
              <td id="dutyCycleAddr8" style="vertical-align: top;text-align: left;"></td>
              <td><table style="width:100%"><tr>
                <td id="hmBootstrap" style="width:70%;margin-right: 0px;padding-right: 0px;"><div class="progress"><div name="dutyCycleBar8" class="progress-bar" role="progressbar" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100" style="width:0%"><span id="dutyCycleVal8"></span></div></div></td>
                <td id="hmBootstrap" style="width:30%"><div class="progress" name="carrierSenseCol8"><div name="carrierSenseBar8" class="progress-bar bg-info" role="progressbar" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100" style="width:0%"><span id="carrierSenseVal8"></span></div></div></td> 
              </tr></table></td>
            </tr>
            <tr name="trDutyCycle9" style="display: none">
              <td id="dutyCycleAddr9" style="vertical-align: top;text-align: left;"></td>
              <td><table style="width:100%"><tr>
                <td id="hmBootstrap" style="width:70%;margin-right: 0px;padding-right: 0px;"><div class="progress"><div name="dutyCycleBar9" class="progress-bar" role="progressbar" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100" style="width:0%"><span id="dutyCycleVal9"></span></div></div></td>
                <td id="hmBootstrap" style="width:30%"><div class="progress" name="carrierSenseCol9"><div name="carrierSenseBar9" class="progress-bar bg-info" role="progressbar" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100" style="width:0%"><span id="carrierSenseVal9"></span></div></div></td> 
              </tr></table></td>
            </tr>
            <tr name="trDutyCycle10" style="display: none">
              <td id="dutyCycleAddr10" style="vertical-align: top;text-align: left;"></td>
              <td><table style="width:100%"><tr>
                <td id="hmBootstrap" style="width:70%;margin-right: 0px;padding-right: 0px;"><div class="progress"><div name="dutyCycleBar10" class="progress-bar" role="progressbar" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100" style="width:0%"><span id="dutyCycleVal10"></span></div></div></td>
                <td id="hmBootstrap" style="width:30%"><div class="progress" name="carrierSenseCol10"><div name="carrierSenseBar10" class="progress-bar bg-info" role="progressbar" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100" style="width:0%"><span id="carrierSenseVal10"></span></div></div></td> 
              </tr></table></td>
            </tr>
            <tr name="trDutyCycle11" style="display: none">
              <td id="dutyCycleAddr11" style="vertical-align: top;text-align: left;"></td>
              <td><table style="width:100%"><tr>
                <td id="hmBootstrap" style="width:70%;margin-right: 0px;padding-right: 0px;"><div class="progress"><div name="dutyCycleBar11" class="progress-bar" role="progressbar" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100" style="width:0%"><span id="dutyCycleVal11"></span></div></div></td>
                <td id="hmBootstrap" style="width:30%"><div class="progress" name="carrierSenseCol11"><div name="carrierSenseBar11" class="progress-bar bg-info" role="progressbar" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100" style="width:0%"><span id="carrierSenseVal11"></span></div></div></td> 
              </tr></table></td>
            </tr>
            <tr name="trDutyCycle12" style="display: none">
              <td id="dutyCycleAddr12" style="vertical-align: top;text-align: left;"></td>
              <td><table style="width:100%"><tr>
                <td id="hmBootstrap" style="width:70%;margin-right: 0px;padding-right: 0px;"><div class="progress"><div name="dutyCycleBar12" class="progress-bar" role="progressbar" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100" style="width:0%"><span id="dutyCycleVal12"></span></div></div></td>
                <td id="hmBootstrap" style="width:30%"><div class="progress" name="carrierSenseCol12"><div name="carrierSenseBar12" class="progress-bar bg-info" role="progressbar" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100" style="width:0%"><span id="carrierSenseVal12"></span></div></div></td> 
              </tr></table></td>
            </tr>
            <tr name="trDutyCycle13" style="display: none">
              <td id="dutyCycleAddr13" style="vertical-align: top;text-align: left;"></td>
              <td><table style="width:100%"><tr>
                <td id="hmBootstrap" style="width:70%;margin-right: 0px;padding-right: 0px;"><div class="progress"><div name="dutyCycleBar13" class="progress-bar" role="progressbar" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100" style="width:0%"><span id="dutyCycleVal13"></span></div></div></td>
                <td id="hmBootstrap" style="width:30%"><div class="progress" name="carrierSenseCol13"><div name="carrierSenseBar13" class="progress-bar bg-info" role="progressbar" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100" style="width:0%"><span id="carrierSenseVal13"></span></div></div></td> 
              </tr></table></td>
            </tr>
            <tr name="trDutyCycle14" style="display: none">
              <td id="dutyCycleAddr14" style="vertical-align: top;text-align: left;"></td>
              <td><table style="width:100%"><tr>
                <td id="hmBootstrap" style="width:70%;margin-right: 0px;padding-right: 0px;"><div class="progress"><div name="dutyCycleBar14" class="progress-bar" role="progressbar" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100" style="width:0%"><span id="dutyCycleVal14"></span></div></div></td>
                <td id="hmBootstrap" style="width:30%"><div class="progress" name="carrierSenseCol14"><div name="carrierSenseBar14" class="progress-bar bg-info" role="progressbar" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100" style="width:0%"><span id="carrierSenseVal14"></span></div></div></td> 
              </tr></table></td>
            </tr>
            <tr name="trDutyCycle15" style="display: none">
              <td id="dutyCycleAddr15" style="vertical-align: top;text-align: left;"></td>
              <td><table style="width:100%"><tr>
                <td id="hmBootstrap" style="width:70%;margin-right: 0px;padding-right: 0px;"><div class="progress"><div name="dutyCycleBar15" class="progress-bar" role="progressbar" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100" style="width:0%"><span id="dutyCycleVal15"></span></div></div></td>
                <td id="hmBootstrap" style="width:30%"><div class="progress" name="carrierSenseCol15"><div name="carrierSenseBar15" class="progress-bar bg-info" role="progressbar" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100" style="width:0%"><span id="carrierSenseVal15"></span></div></div></td> 
              </tr></table></td>
            </tr>

          </table>
          </td>
        </tr>
        </table>

        <div id="forceUpdate" style="display:none; margin-top:50px; padding:10px;">
          <div style="background-color:#BCC7CB; padding:5px; border:solid 1px;">${forcedUpdateHint}</div>
          <div style="text-align: center; margin-top: 50px;"><a href="/licenseinfo.htm" target="_blank">${lblLicenseInformation}</a></div>
          <div class="StdTableBtn CLASS21701" style="width:50%; margin:25%; margin-top: 50px;" onclick="showMaintenanceCP();">${forcedUpdateBtn}</div>
        </div>
  </div>
</div>

<script type="text/javascript">
  var product = 0;
  WebUI.resize();
  StartPage.showUpdate();
  if (forceUpdate) {
      StartPage.showCurrentFirmware();
      jQuery("#forceUpdate").show();
  } else {
      jQuery("#favSelector").show();
      jQuery("#favView").show();
      StartPage.showUpdate();
      StartPage.showCurrentFirmware();
      StartPage.showAllDeviceFirmware();
      jQuery("#forceUpdate").remove();
  }

  if (isNaN(parseInt(WEBUI_VERSION)) || WEBUI_VERSION == "0.0.0") {
    conInfo("Determine WEBUI_VERSION");
    homematic("Interface.getDeviceDescription", {"interface": "BidCos-RF", "address": "BidCoS-RF"}, function (result) {
      if (result != null) {
        WEBUI_VERSION = result.firmware;
      } else {
        WEBUI_VERSION = "0.0.0";
      }
    });
  }

  translatePage();
  jQuery("#loadingGif").hide();
  jQuery("#tblStartpageInfo").show();
</script>
